<template>
  <div>

  </div>
</template>
<script>
import axios from 'axios'
import qs from 'qs'
import router from '@/global/router.js'
export default {
  mounted() {
    this.login()
  },
  data () {
    return {
    }
  },
  methods: {
    login () {
      let token = this.$route.params.token
      let systemId = this.$route.params.systemId
      let routeName = this.$route.params.routeName
      let payload = this.$route.params.payload

      let params = { token, systemId,}
      axios({
        method: 'post',
        url: '/infra/security/tokenLogin',
        data: qs.stringify(params),
      }).then(res=>{
        let data = res.data || {}
        let authToken = data.authToken
        localStorage.setItem('authToken', authToken)
        axios.defaults.headers.common['Authorization'] = authToken


        if (!authToken) {
          router.push({ name: 'Index' })
        } else {
          payload = decodeURIComponent(payload)
          payload = JSON.parse(payload)

          router.push({ name: routeName, params: payload })
        }
        
      }).finally(()=>{
      })
    },
  },
}
</script>